<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ page import="com.DBCon" %>
    <%@ page import="java.sql.*" %>
    <%@ page import="java.text.*" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>学院打卡情况</title>
<%@ include file="../bootstrap.jsp"%>
</head>
<body>
<%
//查询各学院教师人数的sql语句1
String sql1="SELECT Count(TeaId) AS DepTeaSum,DepName FROM teacher GROUP BY DepName";
//查询各学院教师打卡人数的sql语句2
String sql2="SELECT COUNT(TeaId) AS CheckTeaNum,teastatistics.Date,IsCheck,DepName "+
            "FROM teastatistics  WHERE DATE(teastatistics.DATE)=DATE(curdate()) AND IsCheck='已完成' GROUP BY DepName";
try {
	ResultSet rs1;
	ResultSet rs2;
	rs1 = new DBCon().find(sql1);
	rs2 = new DBCon().find(sql2);
	
	//获取页码
	int item = 7; //每一页显示数据项
	int pg = 1; //初始页码
	String p1 =(String)request.getAttribute("p");
	String p2 =request.getParameter("p");
	//如果接收的是页面传递的参数(Parameter 返回的一定是字符串)
	if (p1 != null && p1.length() > 0) {
		pg = Integer.parseInt(p1);
	}else if(p2 != null && p2.length() > 0){
		//如果接收的是Servlet传递的参数(Attribute 返回的是一个对象)
		pg = Integer.parseInt(p2);
	}
	//计算起始位置和结束位置
	rs1.last();
	int count = rs1.getRow(); //获取全部记录行数
	System.out.println(count);

	int start = (pg - 1) * item;
	int limit = pg * item < count ? pg * item : count;
	if (start > 0) {
		rs1.absolute(start);
	} else {
		rs1.beforeFirst();
	}
	System.out.println(start + "-" + limit);
	%>
<h4 style="font-weight: bolder; left: 20px">学院打卡情况</h4>
		<nav class="navbar navbar-light bg-light">
			<ul class="pagination">
				<!-- 显示上一页和下一页分页按钮 -->
				<%
				if (pg == 1) {
				%>
				<li class="page-item disabled "><a class="page-link">上一页</a></li>
				<%
				}
				if (pg > 1) {
				%>
				<li class="page-item "><a class="page-link"
					href="DepCheckList.jsp?p=<%=pg - 1%>">上一页</a></li>
				<%
				}
				if (pg * item < count) {
				%>
				<li class="page-item"><a class="page-link"
					href="DepCheckList.jsp?p=<%=pg + 1%>">下一页</a></li>
				<%
				} else if (pg * item >= count) {
				%>
				<li class="page-item disabled"><a class="page-link">下一页</a></li>
				<%
				}
				%>
			</ul>
		</nav>
	<table class="table table-striped">
		<tr align="center">
			<th scope="col">学院名称</th>
			<th scope="col">已打卡教师人数</th>
			<th scope="col">总教师人数</th>
			<th scope="col">打卡完成百分比</th>		
		</tr>
	<%
	while(rs1.next()&&rs2.next()&&rs1.getRow() <= limit){
		//学院教师人数
		int DepTeaSum=rs1.getInt("DepTeaSum");
		//学院已打卡教师人数
		int CheckTeaNum=rs2.getInt("CheckTeaNum");
		//完成进度百分比
		float f1=(float) CheckTeaNum*1.0f/DepTeaSum;
		//将float转化为百分数
		NumberFormat fmt = NumberFormat.getPercentInstance();
		fmt.setMaximumFractionDigits(2);
		String CheckPercent=fmt.format(f1);
		String progress_valuenow=CheckPercent.substring(0,CheckPercent.length()-1);
		String progress_style="width:"+CheckPercent;
		%>
		<tr align="center">
			<td><%=rs1.getString("DepName")%></td>
			<td><%=CheckTeaNum%></td>
			<td><%=DepTeaSum%></td>
			<td>
				<div class="progress">
					<div class="progress-bar" role="progressbar"
						aria-valuenow=<%=progress_valuenow%> style=<%=progress_style%>
						aria-valuemin="0" aria-valuemax="100"><%=CheckPercent%></div>
				</div>
			</td>
		</tr>
	<%
	}
} catch (Exception e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
}
%>
</table>
</body>
</html>